package com.xlf.service.base.controller.admin;

import com.xlf.common.core.pojo.mode.AjaxResult;
import com.xlf.common.core.pojo.mode.BaseController;
import com.xlf.pojo.base.Language;
import com.xlf.pojo.base.ProblemType;
import com.xlf.service.base.service.LanguageService;
import com.xlf.service.base.service.ProblemLanguageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.xlf.common.core.util.page.PageUtils.startPage;

/**
 * @Author xlf 2734029211@qq.com
 * @Date 2023/11/26 15:22
 * @Description: TODO
 * @Version 1.0
 */
@RestController
@RequestMapping("/base/admin/languages")
public class AdminLanguagesController extends BaseController {

    @Autowired
    LanguageService languageService;

    @GetMapping("/list")
    @PreAuthorize("@ss.hasPermi('base:admin:languages:list')")
    public AjaxResult list(Language language){
        startPage();
        return success(getDataTable(languageService.getList(language)));
    }

    @PostMapping("/saveOrUpdate")
    @PreAuthorize("@ss.hasPermi('base:admin:languages:saveOrUpdate')")
    public AjaxResult saveOrUpdate(@RequestBody Language language){
        return success(languageService.saveOrUpdate(language));
    }


    @GetMapping("/query/{id}")
    @PreAuthorize("@ss.hasPermi('base:admin:languages:query')")
    public AjaxResult query(@PathVariable(value = "id") String id){
        return success(languageService.getById(id));
    }

    @DeleteMapping("/delete")
    @PreAuthorize("@ss.hasPermi('base:admin:languages:delete')")
    public AjaxResult delete(@RequestBody List<String> ids){
        languageService.delete(ids);
        return success("删除成功！");
    }

    @PutMapping("/disabled")
    @PreAuthorize("@ss.hasPermi('base:admin:languages:disabled')")
    public AjaxResult updateStatus(@RequestBody Language language){
        return success(languageService.updateStatus(language));
    }
}
